package com.live.dengdengtv.activity.setting;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.live.dengdengtv.BaseActivity;
import com.live.dengdengtv.R;
import com.live.dengdengtv.utils.DataCleanManager;
import com.live.dengdengtv.utils.Notice;

/**
 * Created by wyf on 2016/8/5.
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener{


    private TextView set_cache_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initTitle();
        initView();
    }

    private void initView() {
        set_cache_tv = (TextView) findViewById(R.id.set_cache_tv);

        String totalCacheSize = "";
        try {
            totalCacheSize = DataCleanManager.getTotalCacheSize(context);
            set_cache_tv.setText(totalCacheSize);
        } catch (Exception e) {
            e.printStackTrace();
        }

        findViewById(R.id.set_cache_rl).setOnClickListener(this);

    }

    private void initTitle() {
        ImageView title_left_iv = (ImageView) findViewById(R.id.title_left_iv);
        title_left_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        TextView title_center_tv = (TextView) findViewById(R.id.title_center_tv);
        title_center_tv.setText("设置");

        TextView title_right_tv = (TextView) findViewById(R.id.title_right_tv);
        title_right_tv.setText("");
    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()){
            case R.id.set_accountsafe_tv:
                intent.setClass(context, AccountSafeActivity.class);
                break;
            case R.id.set_blacklist_tv:
                intent.setClass(context, BlacklistActivity.class);
                break;
            case R.id.set_notice_tv:
                intent.setClass(context, PushActivity.class);
                break;
            case R.id.set_help_tv:
                intent.setClass(context, HelpActivity.class);
                break;
            case R.id.set_cache_rl:
                cleanCach();
                return;
            default: return;
        }

        startActivityForResult(intent, 100);
    }

    private void cleanCach() {
        Notice.alert(context, "确定清理缓存?", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DataCleanManager.clearAllCache(context);
                Toast.makeText(context,"已清理",Toast.LENGTH_SHORT).show();
                set_cache_tv.setText("0B");
            }
        });

    }
}
